﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace myMoney.Finance
{
    public partial class ucRecord : UserControl
    {
        #region Attributes

        public string type = "0";
        public DateTime start = DateTime.Now;
        public DateTime end = DateTime.Now;

        #endregion

        #region UserControl

        public ucRecord()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (type == "1") this.cbExpenses.Checked = true;
            else this.cbIncome.Checked = true;

            this.dtpStart.Value = start;
            this.dtpEnd.Value = end;

            btnCheck_Click(this.btnCheck, new EventArgs());
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            this.statusStrip1.BackColor = Main.AeroColor;
        }

        #endregion

        #region Event

        #region Button

        private void btnCheck_Click(object sender, EventArgs e)
        {
            if (!(this.cbIncome.Checked || this.cbExpenses.Checked))
            {
                MessageBox.Show("请选择收支类型");
                return;
            }

            List<string> type = new List<string>();
            if (this.cbIncome.Checked) type.Add("0");
            if (this.cbExpenses.Checked) type.Add("1");

            DataTable dt = MoneyClass.Expenses.get(Main.CurrentGuid, type, this.dtpStart.Value.ToString("yyyy-MM-dd"), this.dtpEnd.Value.AddDays(1).ToString("yyyy-MM-dd"));
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.Columns[0].DataPropertyName = "typeText";
            this.dgvList.Columns[1].DataPropertyName = "thisDate";
            this.dgvList.Columns[2].DataPropertyName = "ident";
            this.dgvList.Columns[3].DataPropertyName = "classify";
            this.dgvList.Columns[4].DataPropertyName = "money";
            this.dgvList.Columns[5].DataPropertyName = "comment";
            this.dgvList.DataSource = dt;
            this.dgvList.AutoResizeColumns();
        }

        #endregion

        #region DataGridView

        private void dgvList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            this.tsslMsg.Text = string.Format("共{0}条记录", this.dgvList.RowCount);
        }

        private void dgvList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            this.tsslPosition.Text = string.Format("        行 {0}  列 {1}", e.RowIndex + 1, e.ColumnIndex + 1);
        }

        #endregion

        #endregion
    }
}
